package com.bsoft.gol.editor.service.impl;

import com.bsoft.gol.editor.utils.CommonUtils;

import com.bsoft.gol.editor.dao.EditorWidgetClassDAO;
import com.bsoft.gol.editor.editor.EditorWidgetClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bsoft.gol.editor.service.EditorWidgetClassApi;

import java.util.List;
import java.util.UUID;


/**
 * 控件分类表
 * @author sumu
 */
@Service("editorWidgetClassApi")
public class EditorWidgetClassApiImpl implements EditorWidgetClassApi {
    private static Logger logger = LoggerFactory.getLogger(EditorWidgetClassApiImpl.class);

    @Autowired
    private EditorWidgetClassDAO editorWidgetClassDAO;

    @Override
    public String addOrEdit(String classId, String className) {

        if (CommonUtils.isNotEmpty(classId)) {

            editorWidgetClassDAO.updateEditorWidgetClassName(classId,className);
            return classId;
        }else {
            EditorWidgetClass editorWidgetClass = new EditorWidgetClass();
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            editorWidgetClass.setWidgetClassId(uuid);
            editorWidgetClass.setWidgetClassName(className);
            editorWidgetClassDAO.save(editorWidgetClass);
            return uuid;
        }

    }

    @Override
    public List<EditorWidgetClass> list() {
        EditorWidgetClass editorWidgetClass = new EditorWidgetClass();
        return editorWidgetClassDAO.queryEditorWidgetClassAll();
    }

    @Override
    public void delete(String classId) {
        editorWidgetClassDAO.remove(classId);
    }
}